package net.jjjshop.supplier.controller.lbt;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import net.jjjshop.common.entity.lbt.BusinessOrderRequest;
import net.jjjshop.common.entity.lbt.TradeOrderEntityRequest;
import net.jjjshop.common.service.lbt.TradeOrderService;
import net.jjjshop.common.service.lbt.TradeService;
import net.jjjshop.framework.common.api.ApiResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/supplier/store/trade")
@Api(tags = "权益卡管理")
@Validated
public class TradeController {

    @Autowired
    private TradeService tradeService;
    @Autowired
    private TradeOrderService tradeOrderService;


    //@PreAuthorize("hasAuthority('admin:trade:getSaleList')")
    @ApiOperation(value = "挂卖 回收分页列表")
    @RequestMapping(value = "/getSaleList", method = RequestMethod.GET)
    public ApiResult<IPage<BusinessOrderRequest>> getSaleList(@ModelAttribute @Validated BusinessOrderRequest request,
                                                                 Integer page,Integer limit) {
        return ApiResult.ok(tradeService.getSaleList(request, page,limit));
    }

    //@PreAuthorize("hasAuthority('admin:trade:getTradeOrderList')")
    @ApiOperation(value = "交易订单分页列表")
    @RequestMapping(value = "/getTradeOrderList", method = RequestMethod.GET)
    public ApiResult<IPage<TradeOrderEntityRequest>> getTradeOrderList(@ModelAttribute @Validated TradeOrderEntityRequest request,
                                                                            Integer page, Integer limit) {
        return ApiResult.ok(tradeOrderService.getTradeOrderList(request, page,limit));
    }

    @ApiOperation(value = "取消交易订单")
    @RequestMapping(value = "/cancelOrder", method = RequestMethod.POST)
    public ApiResult<?> cancelOrder(@ModelAttribute @Validated TradeOrderEntityRequest request) {
        Boolean order = tradeOrderService.cancelOrder(request);
        if (order){
            return ApiResult.ok("操作成功");
        }
       return ApiResult.fail("操作失败");
    }







}
